-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: updating mocks for tests to test mender-connect JWT request handling #2108
base: master
Are you sure you want to change the base?
Conversation
@SebOpsahl, Let me know if you want to start the integration pipeline by mentioning me and the command "start pipeline". my commands and optionsYou can trigger a pipeline on multiple prs with:
You can start a fast pipeline, disabling full integration tests with:
You can trigger GitHub->GitLab branch sync with:
You can cherry pick to a given branch or branches with:
|
b864e2d
to
b7a8fb9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work getting the mock to behave and the tests passing 💪
I think however that we have introduced many unjustified changes in the test flow, and I'd like to discuss or revert them (see comments below).
Your commit is pretty good. Some tips to make it better:
- Generally speaking, we are changing the mock and the test flow to accommodate for the changes in the software (your title and description only focuses on the mock)
- You put a link to "the other PR" in your commit message 👉 fix: Fix to make mender-connect request a new JWT token on its own, so its not dependent on mender-update to do so mender-connect#134
</interface> | ||
</node> | ||
""" | ||
<node> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No objections on changing from tabs to spaces 👍 This was probably what got your editor confused.
</method> | ||
<signal name="JwtTokenStateChange"> | ||
<arg type="s" name="token"/> | ||
<arg type="s" name="server_url"/> | ||
</signal> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicpick: wrong indentation
</method> | |
<signal name="JwtTokenStateChange"> | |
<arg type="s" name="token"/> | |
<arg type="s" name="server_url"/> | |
</signal> | |
</method> | |
<signal name="JwtTokenStateChange"> | |
<arg type="s" name="token"/> | |
<arg type="s" name="server_url"/> | |
</signal> |
@@ -193,14 +202,18 @@ def test_mender_connect_auth_changes( | |||
"""Test that mender-connect can re-establish the connection on D-Bus signals""" | |||
|
|||
try: | |||
dbus_set_token_and_url(connection, "token1", "http://localhost:5000") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this we should keep as it was. The test scenario here is that the server is up and running already when mender-connect
starts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happened here? I still believe that we should simulate that the server is up and running before mender-connect starts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okey, since the tests fail due to timeout when we first set the token and url, and then let mender-connect start. But is successful when we do it after mender-connect has started. I will investigate the issue 👍
dbus_set_token_and_url(connection, "token1", "http://localhost:5000") | ||
|
||
# sleep for a while to ensure a connection happens | ||
time.sleep(60) | ||
dbus_emit_signal(connection) | ||
signal_time = qemu_system_time(connection) | ||
|
||
# wait for first connect | ||
_ = wait_for_string_in_log( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sleep here looks suspicious to me. The wait_for_string_in_log
function below will wait a given amount of time for the required message, so we shouldn't need to wait before.
You probably meant to wait for mender-connect
to start-up before we can instruct the mock to emit the signal, so that will be short sleep between systemctl ... start mender-connect
and dbus_emit_signal
.
A much better approach that we draft some time ago on the whiteboard would be to have a flag in the mock that can save when mender-connect
has called FetchJwtToken
and then the test can wait for that to then emit the signal. This is a bit more complex but will be a better test (right now we are blindly assuming that mender-connect
requested a token before we emit the signal).
dbus_set_token_and_url(connection, "token2", "http://localhost:6000") | ||
time.sleep(30) | ||
signal_time = qemu_system_time(connection) | ||
dbus_set_token_and_url_and_emit_signal( | ||
connection, "token2", "http://localhost:6000" | ||
) | ||
dbus_emit_signal(connection) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should stay as it was, why we need to sleep between setting state in the mock and emitting the signal?
@@ -277,14 +290,18 @@ def test_mender_connect_reconnect( | |||
"""Test that mender-connect can re-establish the connection on remote errors""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much of what I commented in the previous test case is applicable to this one, so I won't review it in detail just yet 👀
_ = wait_for_string_in_log( | ||
connection, kill_time, 300, "error reconnecting:", | ||
connection, kill_time, 300, "waiting for reconnect", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why won't in this case eventually come back to error reconnecting
? What has changed in mender-connect
for this case? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on returns made in the the tests it returned waiting for reconnect given the test case, while the test was made to wait for error reconnecting which made it fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okey
691c712
to
702954b
Compare
…connect This PR is made to change the mocks and testflow in tests to better fit the new implementation of the PR 👉 mendersoftware/mender-connect#134. This PR fixes it so `mender-connect` requests a new JWT token on its own, so its not dependent on `mender-update` to do so. Previously `FetchJWTToken()` wasn’t called which wouldn’t let it call the JWT token independently, which made it dependent on `mender-update`. The proposed fix is using `FetchJWTToken()` to fetch the token, to then for `WaitForJwtTokenStateChange()` to retrieve it in it’s waiting. The old mocks and test flow for the tests seemed to be more tailored to test the functionality with `GetJWTToken()`. This PR proposes a change in the mocks and test flow to better test the new implementation. Changelog: None Ticket: MEN-6877 Signed-off-by: Sebastian Opsahl <[email protected]>
With the new changes made to the actual implementation of the ticket found here 👉 mendersoftware/mender-connect#134 (comment) and the new test implementation where the test ensures an connection instead of just sleeping and assuming an connection everything should look good |
@mender-test-bot start pipeline --pr mender-connect/134 |
Hello 😺 I created a pipeline for you here: Pipeline-1306885344 Build Configuration Matrix
|
</node> | ||
""" | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not a big deal, though. But for the future:
Changing the indentation is unrelated to your changes. The commit would read much cleaner if we could have here only the method that we have added. If you want to modify the indentation it is best to do it on a separate commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, the formatting test wouldn't pass unless i changed the formatting. I thought it may have been something with the formatter being updated. Is there any way I can come around the failing test without changing the formatting of the other parts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, the formatting test wouldn't pass unless i changed the formatting. I thought it may have been something with the formatter being updated. Is there any way I can come around the failing test without changing the formatting of the other parts?
I am not aware of any recent change. We use a fixed version of the formatting tool.
But in any case you could have formatted the existing code first, commit that, then add your changes.
Again, this is not a big deal so don't spend more time on it.
@@ -193,14 +202,18 @@ def test_mender_connect_auth_changes( | |||
"""Test that mender-connect can re-establish the connection on D-Bus signals""" | |||
|
|||
try: | |||
dbus_set_token_and_url(connection, "token1", "http://localhost:5000") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happened here? I still believe that we should simulate that the server is up and running before mender-connect starts.
connection, startup_time, 30, "Started Mender Connect service" | ||
) | ||
|
||
signal_time = qemu_system_time(connection) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we use signal_time
below (line 224) when looking for "Connection established..." in the log?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry my bad, fixed it now 👍
connection, startup_time, 30, "Started Mender Connect service" | ||
) | ||
|
||
signal_time = qemu_system_time(connection) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it now 👍
@@ -277,14 +294,22 @@ def test_mender_connect_reconnect( | |||
"""Test that mender-connect can re-establish the connection on remote errors""" | |||
|
|||
try: | |||
dbus_set_token_and_url(connection, "badtoken", "http://localhost:12345") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, the serer is expected to be running before mender-connect starts
_ = wait_for_string_in_log( | ||
connection, kill_time, 300, "error reconnecting:", | ||
connection, kill_time, 300, "waiting for reconnect", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okey
# kill the server and wait for error | ||
with_mock_servers[1].kill() | ||
kill_time = qemu_system_time(connection) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is probably unnecessary and I vote for reverting it. It is in effect the same thing, but capturing the time before the action (in this case before killing the server) makes it consistent across the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it now :)
This PR is made to change the mocks and testflow in tests to better fit the new implementation of the PR 👉 mendersoftware/mender-connect#134. This PR fixes it so
mender-connect
requests a new JWT token on its own, so its not dependent onmender-update
to do so. PreviouslyFetchJWTToken()
wasn’t called which wouldn’t let it call the JWT token independently, which made it dependent onmender-update
. The proposed fix is usingFetchJWTToken()
to fetch the token, to then forWaitForJwtTokenStateChange()
to retrieve it in it’s waiting. The old mocks and test flow for the tests seemed to be more tailored to test the functionality withGetJWTToken()
. This PR proposes a change in the mocks and test flow to better test the new implementation.Changelog: None
Ticket: MEN-6877